﻿namespace Smark.Core
{
    using System;
    using System.Collections.Specialized;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;

    [Serializable]
    public class XMLNameValueCollection : NameValueCollection, IXmlSerializable
    {
        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            XmlSerializer xmlSerializer = Functions.GetXmlSerializer(typeof(string), null);
            XmlSerializer serializer2 = Functions.GetXmlSerializer(typeof(string), null);
            bool isEmptyElement = reader.IsEmptyElement;
            reader.Read();
            if (!isEmptyElement)
            {
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    reader.ReadStartElement("item");
                    reader.ReadStartElement("key");
                    string name = (string) xmlSerializer.Deserialize(reader);
                    reader.ReadEndElement();
                    reader.ReadStartElement("value");
                    string str2 = (string) serializer2.Deserialize(reader);
                    reader.ReadEndElement();
                    this.Add(name, str2);
                    reader.ReadEndElement();
                    reader.MoveToContent();
                }
                reader.ReadEndElement();
            }
        }

        public void WriteXml(XmlWriter writer)
        {
            XmlSerializer xmlSerializer = Functions.GetXmlSerializer(typeof(string), null);
            XmlSerializer serializer2 = Functions.GetXmlSerializer(typeof(string), null);
            foreach (string str2 in this.Keys)
            {
                string o = base[str2];
                if (o != null)
                {
                    writer.WriteStartElement("item");
                    writer.WriteStartElement("key");
                    xmlSerializer.Serialize(writer, str2);
                    writer.WriteEndElement();
                    writer.WriteStartElement("value");
                    serializer2.Serialize(writer, o);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
            }
        }
    }
}

